<template>
  <Input size="large" v-model="keyword" @on-click="enter" @on-enter="enter" icon="search" placeholder="输入查询的信息"
         style="width: 400px"/>
</template>

<script>

  import store from '@/store/global'

  export default {
    props: ['tab'],
    store: store,
    data () {
      return {
        keyword: _.get(this.$store, 'state.searchKeyword')
      }
    },
    computed: {
      ...Vuex.mapState(['searchKeyword', 'searchTab'])
    },
    watch: {
      searchKeyword () {
        this.keyword = this.searchKeyword
      }
    },
    methods: {
      enter () {
        this.$router.push({
          name: 'Search',
          params: {
            content: this.keyword,
            tab: this.searchTab
          }
        })
      }
    },
    mounted () {
      if (this.tab) {
        store.commit('changeSearchTab', this.tab)
      }
    }
  }
</script>
